<?php

namespace server\dao;

use Yii;
use yii\db\Query;

/**
 * This is the model class for table "equ_computer".
 *
 * @property int|null $id
 * @property int|null $station_id
 * @property int|null $lane_id
 * @property string $name
 * @property string $ip
 * @property int $status
 * @property int $created_at
 * @property int $updated_at
 */
class EquComputer extends \common\core\server\ActiveRecord
{
    /**
     * {@inheritdoc}
     */
    public static function tableName()
    {
        return 'equ_computer';
    }

    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['line_id','station_id', 'lane_id', 'status', 'created_at', 'updated_at'], 'integer'],
            [['name', 'ip','control_ip','remote_username','remote_password','protocol'], 'string', 'max' => 255],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'line_id' => 'Line ID',
            'station_id' => 'Station ID',
            'lane_id' => 'Lane ID',
            'name' => 'Name',
            'protocol' => 'Protocol',
            'remote_username' => 'Remote Username',
            'remote_password' => 'Remote Password',
            'ip' => 'Ip',
            'control_ip' => 'Control Ip',
            'status' => 'Status',
            'created_at' => 'Created At',
            'updated_at' => 'Updated At',
        ];
    }

    public function getComputeList($params = [], $isAll = true)
    {
        $query = new Query();
        $query->from($this->tableName());
        if ($params['type'] == 1) {
            $query->andWhere(['line_id' => $params['id']]);
        } elseif ($params['type'] == 2) {
            $query->andWhere(['station_id' => $params['id']]);
        }
        /*if ($this->issetAndEmpty($params, 'station_id')) {
            $query->andWhere(['station_id' => $params['station_id']]);
        }*/

        //return $query->createCommand()->getRawSql();
        return $isAll ? $query->all() : $this->$this->page($query);
    }


}
